const HOST = require('../../../config.js').host

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    titles: [],
    quesetionCollect:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadData();
  },

  
  show(e)
  {
  
    var questionData = this.data;
    const section = parseInt(e.currentTarget.dataset.section);
    const row = parseInt(e.currentTarget.dataset.row);
    let title = questionData.titles[section];

    var questionCollect = questionData.quesetionCollect;
    var question = questionCollect[title][row];
    if (question.onOff == true)
    {
      question.onOff = false;
    } else {
      question.onOff = true;
    }
    this.setData({
      quesetionCollect: questionCollect
    })
  },
  loadData ()
  {
    let self = this;
    var titleAry = [];
    wx.request({
      url: HOST + 'v1/answerquestion/findAllOrderBySort',
      method: 'GET',
      success(res) {
        if (res.data.sysCode === 1) {
          for (let key in res.data.data) {
            titleAry.push(key);
          }
          self.setData({
            quesetionCollect: res.data.data,
            titles:titleAry,
          })
        }
      }
    })
  }
})